package com.bsg.upm.controller;

 

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import org.springframework.web.bind.annotation.ResponseBody;

import com.bsg.upm.exception.APIException;
import com.bsg.upm.http.RespJson;
import com.bsg.upm.http.RespJsonFactory;
import com.bsg.upm.service.DashboardService;

/**
 * 
 * @author yucs
 *
 */
@Controller
@RequestMapping("/v1.0/dashboards")
public class DashboardController {
	
	@Resource
	private DashboardService dashboardService;
	@RequestMapping(value = "/{site_id}/info", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getSiteCommonInfo(@PathVariable("site_id") String siteId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = dashboardService.getSiteInfo(siteId);
			response.setStatus(respJson.getStatus());
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}

	@RequestMapping(value = "/{site_id}/resource", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getMonitorResource(@PathVariable("site_id") String siteId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = dashboardService.getMonitorResource(siteId);
			response.setStatus(respJson.getStatus());
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}
	
	@RequestMapping(value = "/{site_id}/alarminfo", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getMonotorAlarmResource(@PathVariable("site_id") String siteId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = dashboardService.getMonotorAlarmResource(siteId);
			response.setStatus(respJson.getStatus());
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}
	
	@RequestMapping(value = "/{cluster_id}/clusterinfo", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getClusterInfo(@PathVariable("cluster_id") String clusterId, HttpServletResponse response) {
		RespJson respJson = null;
		try {
			respJson = dashboardService.getClusterInfo(clusterId);
			response.setStatus(respJson.getStatus());
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}
	
	@RequestMapping(value = "{site_id}/orders", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getOrderStatus(@PathVariable("site_id") String siteId,HttpServletRequest request,  HttpServletResponse response) {
		RespJson respJson = null;
		try {
 
			respJson = dashboardService.getOrderStatus(siteId);
			response.setStatus(respJson.getStatus());
			
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}
	
	@RequestMapping(value = "{site_id}/subserv_status", method = RequestMethod.GET)
	@ResponseBody
	public RespJson getSubServStatus(@PathVariable("site_id") String siteId,HttpServletRequest request,  HttpServletResponse response) {
		RespJson respJson = null;
		try {
 
			respJson = dashboardService.getServStatus(siteId);
			response.setStatus(respJson.getStatus());
			
		} catch (APIException e) {
			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		}
		return respJson;
	}

//	@Resource
//	private DashboardService dashboardService;
//
//	/**
//	 * 【工单状态查询】
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param paramMap
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "orders", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson getOrderStatus(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("siteId", paramMap.get("site_id"));
//			respJson = dashboardService.getOrderStatus(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}
//
//	/**
//	 * 
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param paramMap
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "resources-used", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson getResourcesUsed(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("siteId", paramMap.get("site_id"));
//			respJson = dashboardService.getResourcesUsed(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}
//
//	/**
//	 * 
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param param
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "cluster-resources-allocation", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson getClusterResourcesAllocation(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("clusterId", paramMap.get("cluster_id"));
//			respJson = dashboardService.getClusterResourcesAllocation(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}
//
//	/**
//	 * 【服务状态查询】
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param paramMap
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "serv-status", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson getServStatus(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("siteId", paramMap.get("site_id"));
//			searchParamMap.put("definitionServId", paramMap.get("definition_serv_id"));
//			respJson = dashboardService.getServStatus(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}
//
//	/**
//	 * 
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param paramMap
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "serv-resources-allocation", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson getServResourcesAllocation(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("servId", paramMap.get("serv_id"));
//			respJson = dashboardService.getServResourcesAllocation(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}
//
//	/**
//	 * 
//	 * 
//	 * @param request
//	 *            HttpServletRequest对象
//	 * @param param
//	 *            请求参数
//	 * @return 操作结果
//	 */
//	@RequestMapping(value = "serv-ops", method = RequestMethod.GET)
//	@ResponseBody
//	public RespJson listServQps(HttpServletRequest request, @RequestParam Map<String, Object> paramMap, HttpServletResponse response) {
//		RespJson respJson = null;
//		try {
//			Map<String, Object> searchParamMap = new HashMap<String, Object>();
//			searchParamMap.put("servId", paramMap.get("serv_id"));
//			respJson = dashboardService.getServOpsOrQps(request, searchParamMap);
//			response.setStatus(respJson.getStatus());
//		} catch (APIException e) {
//			response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
//			respJson = RespJsonFactory.build(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage());
//		}
//		return respJson;
//	}

}
